﻿using CleanArchitecture.Infrastructure.Entities.Business;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CleanArchitecture.Infrastructure.DataMapping.Business
{
    /// <summary>
    /// Mapping class
    /// </summary>
    public partial class FileBinaryMap : NowaEntityTypeConfiguration<FileBinary>
    {
        #region Methods

        /// <summary>
        /// Configures the entity
        /// </summary>
        /// <param name="builder">The builder to be used to configure the entity</param>
        public override void Configure(EntityTypeBuilder<FileBinary> builder)
        {
            builder.ToTable("bus_filebinary");
            builder.HasKey(fileBinary => fileBinary.Id);
            builder.Property(fileBinary => fileBinary.FKFileUploadId).HasColumnName("FK_FileUploadId");

            builder.HasOne(fileBinary => fileBinary.FileUpload)
                .WithOne(file => file.FileBinary)
                .HasForeignKey<FileBinary>(fileBinary => fileBinary.FKFileUploadId)
                .OnDelete(DeleteBehavior.Cascade);

            base.Configure(builder);
        }

        #endregion
    }
}
